package org.jimmy.tang.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author jimmy
 * 
 */
public class ArrayToList {

    public static void main(String... arg) {
        Employee jim = new Employee("Jim");
        Employee bob = new Employee("Bob");
        Employee gin = new Employee("Gin");

        /************ List to Array ********************************/
        List<Employee> staff = new ArrayList<Employee>();
        staff.add(jim);
        staff.add(bob);
        staff.add(gin);
        System.out.println(staff);// [Name:Jim, Name:Bob, Name:Gin]

        Employee[] e = new Employee[staff.size()];
        staff.toArray(e);
        for (Employee em : e) {
            System.out.println(em);
            /* 
             * Name:Jim 
             * Name:Bob 
             * Name:Gin 
             * */
        }

        /************ Array to List ********************************/
        List<Employee> arrayToList = Arrays.asList(e);
        System.out.println(arrayToList.get(2));// Name:Gin

    }
}

class Employee {
    public Employee(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Name:" + name;
    }

    private String name = "";// 实例域初始化
}